package com.wc.AlgoOJ_homework.AlOJ模块测试I.G_修路;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/12 10:20
 * @description http://43.138.190.70:8888/p/591?tid=663e1b10d39d10926ed3f7fa
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 2010;
    static int[] a = new int[N], b = new int[N];
    // f[i][j][k] 表示a已经走了i步, b已经走了j步, k = 0在上面, k = 1在下面
    static double[][][] f = new double[N][N][2];
    static double INF = 1e25;
    static int n, m, d;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        d = sc.nextInt();
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        for (int i = 1; i <= m; i++) b[i] = sc.nextInt();
        Arrays.sort(a, 1, n + 1);
        Arrays.sort(b, 1, m + 1);
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= m; j++) {
                Arrays.fill(f[i][j], INF);
            }
        }
        f[0][0][0] = 0;
        f[0][0][1] = d;
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j <= m; j++) {
                // 从i - 1, j, 0 -> i, j, 0
                // 从i - 1, j, 1 -> i, j, 0
                if (i - 1 >= 0)
                    f[i][j][0] = Math.min(f[i - 1][j][0] + a[i] - a[i - 1], f[i - 1][j][1] + work(a[i], b[j]));
                // 从i, j - 1, 1 -> i, j, 1
                // 从i, j - 1, 0 -> i, j, 1
                if (j - 1 >= 0)
                    f[i][j][1] = Math.min(f[i][j - 1][1] + b[j] - b[j - 1], f[i][j - 1][0] + work(a[i], b[j]));
            }
        }
        out.printf("%.2f\n", Math.min(f[n][m][0], f[n][m][1]));
        out.flush();
    }

    static double work(double a, double b) {
        double dx = a - b, dy = d;
        return Math.sqrt(dx * dx + dy * dy);
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
